import { Controller, Get, Post, Body, Patch, UseFilters, UseGuards,Request } from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { TypeormFilter } from 'src/common/filters/typeorm.filter';
import { JwtGuard } from 'src/common/guards/jwt.guard';
import { AdminService } from './admin.service';
import { EditInfoDto } from './dto/edit-info.dto';
import { EditPasswordDto } from './dto/edit-password.dto';
import { LoginDto } from './dto/login.dto';
import { CaptchaResultVo } from './vo/captcha.result.vo';
import { EditInfoResultVo } from './vo/edit-info.result.vo';
import { GetInfoResultVo } from './vo/get-info.result.vo';
import { LoginResultVo } from './vo/login.result.vo';

@ApiTags('管理员')
@Controller('admin')
@UseFilters(new TypeormFilter())
export class AdminController {
  constructor(private readonly adminService: AdminService) {}

  @Get('captcha')
  @ApiOperation({summary:'获取验证码'})
  @ApiResponse({
    type:CaptchaResultVo
  })
  captcha() {
    return this.adminService.captcha();
  }

  @Post('login')
  @ApiOperation({summary:'登录'})
  @ApiResponse({
    type:LoginResultVo
  })
  login(@Body() loginDto: LoginDto) {
    return this.adminService.login(loginDto);
  }
  
  @Post('logout')
  @ApiOperation({summary:'退出登录'})
  @ApiResponse({type:null})
  @ApiBearerAuth()
  @UseGuards(JwtGuard)
  logout(@Request() req) {
    return this.adminService.logout(req);
  }

  @Get('getInfo')
  @ApiOperation({summary:'获取信息'})
  @ApiResponse({type:GetInfoResultVo})
  @ApiBearerAuth()
  @UseGuards(JwtGuard)
  getInfo(@Request() req) {
    return this.adminService.getInfo(req);
  }

  @Patch('editInfo')
  @ApiOperation({summary:'修改信息'})
  @ApiResponse({type:EditInfoResultVo})
  @ApiBearerAuth()
  @UseGuards(JwtGuard)
  editInfo(@Request() req,@Body() editInfoDto:EditInfoDto) {
    return this.adminService.editInfo(req,editInfoDto)
  }

  @Patch('editPassword')
  @ApiOperation({summary:'修改密码'})
  @ApiResponse({type:null})
  @ApiBearerAuth()
  @UseGuards(JwtGuard)
  editPassword(@Request() req,@Body() editPasswordDto:EditPasswordDto) {
    return this.adminService.editPassword(req,editPasswordDto)
  }
}
